home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 352_01 / wildpick.cpp < prev   
C/C++ Source or Header  |  1991-04-22  |  1KB  |  56 lines

  1. // WILDPICK.CPP       routine to allow user to select a file from a list
  2. //                    the list is generated from a wildcard spec.
  3. //                 PARM: spec =ptr to filename wildcards. may include drive & path
  4. //                     attr  = file attribute mask, see TurboC++ findfirst()
  5. //                RETURNS: void
  6. //                SIDE EFFECT: the string indicated by parm 1 (spec) is replaced.
  7. //                             the new contents are the selected file name
  8. //                             (which may be up to 8+1+3+1 bytes).
  9. //                             the drive:path name is left out.
  10. //                             stirng set to 0 if no file selected.
  11. //                example:    char  wildcard[8+1+3+1] = "*.cpp";
  12. //                            wildfile_pick ( wildcard, 0 );
  13. //                            ... wildcard now contains name of file selected.
  14. //
  15. #include <stdlib.h>
  16. #include <dir.h>
  17. #include <dos.h>
  18. #include <string.h>
  19.  
  20. #include "wtwg.h"
  21. #include "dblib.h"
  22.  
  23. void  wildfile_pick (char *spec, int attr   )
  24.     {
  25.     int npick;
  26.     char  *choice;
  27.  
  28.  
  29.     Vlist *vl = wildfile (spec, attr);        // make list of matching file
  30.  
  31.     if ( vl->isEmpty() )
  32.         {
  33.         wpromptc ( spec, "ABOVE FILE NOT FOUND", NULL );
  34.         spec[0]= 0;            /* null in caller area */
  35.         }
  36.     else
  37.         {
  38.         npick =wpicklist ( spec, (char**) (*vl) );        // NOTE cast to array.
  39.         choice = (char *)  ( (*vl)[npick] );            // pick up string ptr.
  40.         if ( choice == NULL )
  41.             {
  42.             spec[0] =0;    
  43.             } 
  44.         else
  45.             {
  46.             strcpy ( spec, choice );
  47.             }
  48.         }
  49.         
  50.     delete vl;    // delete vlist created by wildfile().
  51.     
  52.     return;        // wildfile_pick()
  53.     }
  54.  
  55. //----------------- end of WILDPICK.CPP
  56.